package com.gws.juc;

import java.io.PrintStream;
import java.util.Arrays;
import java.util.List;


class User{
	private int id;
	private String userName;
	private int age;
	public User(int id, String userName, int age) {
		super();
		this.id = id;
		this.userName = userName;
		this.age = age;
	}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
	public int getAge() {
		return age;
	}
	public void setAge(int age) {
		this.age = age;
	}
	@Override
	public String toString() {
		return "User [id=" + id + ", userName=" + userName + ", age=" + age
				+ "]";
	}
	
	
	
}

/**
 * 流式计算
 * @author gws
 * 要求：选出id为偶数，年龄大于25，姓名转为大写并且倒序，只要一条数据
 */
public class StreamDemo {
	public static void main(String[] args) {
		User user1 = new User(11, "a", 23);
		User user2 = new User(12, "b", 24);
		User user3 = new User(13, "c", 25);
		User user4 = new User(14, "d", 26);
		User user5 = new User(16, "e", 27);
		
		List<User> list = Arrays.asList(user1,user2,user3,user4,user5);
		
		list.stream().filter(u -> { //选出id为偶数
			return u.getId()%2 == 0;
		}).filter(u -> { //年龄大于25
			return u.getAge()>25;
		}).map(u -> {//姓名转为大写
			return u.getUserName().toUpperCase();
		}).sorted((o1,o2) -> {//倒序
			return o2.compareTo(o1);
		}).limit(1) //一条数据
			.forEach(System.out::println);
		
		
	}

}
